package com.xudow.app.dynamicstate_old.module.collect;

import android.support.annotation.NonNull;

import com.jude.beam.expansion.list.BeamListFragmentPresenter;
import com.xudow.app.dynamicstate_old.data.DynamicModel;
import com.xudow.app.dynamicstate_old.domain.entity.Dynamic;
import com.xudow.app.dynamicstate_old.module.user.UserDynamicFragment;

/**
 * Created by ske on 2016/6/10.
 */
public class CollectDynamicPresenter extends BeamListFragmentPresenter<CollectDynamicFragment, Dynamic> {
    long userId;
    long lastTime;

    @Override
    protected void onCreateView(@NonNull CollectDynamicFragment view) {
        super.onCreateView(view);
        onRefresh();
    }


    @Override
    public void onRefresh() {
        DynamicModel.getInstance()
                .getCollectDynamics(10, 0, 1)
                .doOnNext(list -> {
                    if (list != null && list.size() > 0)
                        lastTime = list.get(list.size() - 1).getPublishTime();
                })
                .doAfterTerminate(() -> getAdapter().notifyDataSetChanged())
                .unsafeSubscribe(getRefreshSubscriber());
    }

    @Override
    public void onLoadMore() {
        DynamicModel.getInstance()
                .getCollectDynamics(10, lastTime, 2)
                .doOnNext(list -> {
                    if (list != null && list.size() > 0)
                        lastTime = list.get(list.size() - 1).getPublishTime();
                })
                .doAfterTerminate(() -> getAdapter().notifyDataSetChanged())
                .unsafeSubscribe(getMoreSubscriber());
    }
}
